import api from '@/api';
import { showToastMsg } from '@/utils/format.js';

const dictionary={
	state: {
		fileType: [], //文件类型 字典 'FILE_TYPE'
		deviceType:[], //设备类型 字典 'DEVICE_TYPE'
		deviceStatus:[] //设备状态 字典 'DEVICE_STATUS'
	},
	mutations: {
		SAVE_FILE_TYPE(state, newList) {
			state.fileType = newList;
		},
		SAVE_DEVICE_TYPE(state, newList) {
			state.deviceType = newList;
		},
		SAVE_DEVICE_STATUS(state, newList) {
			state.deviceStatus = newList;
		},
	},
	actions: {
		/**
		 * @description: 获取角色树
		 * @param {*} 
		 * @return {*}
		 */
		async get_disCode({ commit, dispatch },type){
			if(!type) return 
			let result = {}
			await api.getDicCode({
				dictionaryCode: type
			}).then(res=>{
				result = res;
			}).catch(err=>{
				result = error;
			})
			if(result.code==200 && result.data){
				let arr = []
				for (let key in result.data) {
				  if (result.data.hasOwnProperty(key)) {
				    arr.push({
						text:result.data[key],
						value:key
					})
				  }
				}
				commit('SAVE_'+type, arr)
			}else{
				commit('SAVE_'+type, {})
			}
		},
	}
	
}
export default dictionary;